package com.qitmiaojie.service;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qitmiaojie.mapper.LeaveMapper;
import com.qitmiaojie.pojo.Leave;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Date;

@SpringBootTest
public class LeaveServiceImpl {
    private final static String []times= {"00:00","03:00","06:00","09:00","12:00","15:00","18:00","21:00","24:00"};
    @Autowired
    private LeaveMapper leaveMapper;
    @Autowired
    private LeaveService leaveService;
    @Test
    public void test(){

/*        String date = "2022-07-13T16:00:00.000Z";
        int i1 = date.lastIndexOf("-");
        String substring = date.substring(0, i1+3);
        System.out.println(substring);*/


        Integer []in=new Integer[8];
        Integer []out=new Integer[8];
        for (int i = 0; i < 8; i++) {
            String today= DateUtil.today();
            String startTime = today+ " " +times[i];
            String endTime = today+ " " +times[i+1];

           /* in[i]=leaveMapper.selectDayTimeIn(startTime,endTime);*/
            LambdaQueryWrapper<Leave> inQueryWrapper = new LambdaQueryWrapper<>();
            inQueryWrapper.between(Leave::getStartdate,startTime,endTime);
            inQueryWrapper.ge(Leave::getEnddate,startTime);
            inQueryWrapper.le(Leave::getStartdate,endTime);
            in[i] = leaveService.count(inQueryWrapper);
            LambdaQueryWrapper<Leave> outQueryWrapper = new LambdaQueryWrapper<>();
            /*startdate >= #{timestart} and startdate < #{timeend}")*/
            outQueryWrapper.ge(Leave::getStartdate,startTime);
            outQueryWrapper.le(Leave::getStartdate,endTime);
            out[i]=leaveService.count(outQueryWrapper);
            System.out.println("in = " + in[i].toString() +"    out=  " +  out[i].toString());

        }
    }
}
